package com.lggry.override;

public class Test2 {
    public static void main(String[] args) {
        //目标：方法重写的应用场景:子类重写Object的toString()方法，以便返回对象的内容
        Student stu = new Student("Alan",'男',18);
        System.out.println(stu.toString());
        //注意：直接输出对象，默认会调用Object的toString()方法，返回对象的地址
        //注意：输出对象看内容信息

    }
}

class Student {
    private String name;
    private char gender;
    private int age;

    public Student(){

    }

    public Student(String name, char gender, int age) {
        this.name = name;
        this.gender = gender;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString(){
        return "{name=" + name + ",gender=" + gender + ",age=" + age + "}";
    }
}

